import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/*  Router Modules */

import TeachersRouter from './modules/alecturer'/*
import AnswerRouter from './modules/answer'
import applicationRouter from './modules/application'
import curriculumRouter from './modules/curriculum'
import nestedRouter from './modules/information'
import statisticalRouter from './modules/statistical'
import studentRouter from './modules/student'
*/

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/AuthorityManagement',
    component: Layout,
    redirect: '/AuthorityManagement/index',
    name: 'documentation',
    meta: { title: '系统管理', icon: 'el-icon-s-tools' },
    children: [
      {
        path: 'system',
        component: () => import('@/views/AuthorityManagement/system'),
        name: 'system',
        meta: { title: '权限', icon: 'el-icon-wallet',noCache: true  }
      },
      {
        path: 'Role',
        component: () => import('@/views/AuthorityManagement/Role'),
        name: 'Documentation',
        meta: { title: '角色管理', icon: 'el-icon-s-custom',noCache: true  }
      }
    ]
  },

  {
    path: '/UserManagement',
    component: Layout,
    meta: { title: '用户管理', icon: 'el-icon-user-solid', noCache: true },
    children: [
      {
        path: 'index',
        component: () => import('@/views/UserManagement/index'),
        name: 'User',
        meta: { title: '用户管理', icon: 'el-icon-user-solid', noCache: true }
      },
    ]
  },
  {
    path: '/MediaAdvertisingChart',
    component: Layout,
    redirect: '/MediaAdvertisingChart/export-MediaAdvertisingChart',
    name: 'Excel',
    meta: { title: '媒体广告图', icon: 'el-icon-share' },
    children: [
      {
        path: 'PictureType',
        component: () => import('@/views/MediaAdvertisingChart/PictureType'),
        name: 'AdvertisingChart',
        meta: { title: '广告图' }
      },
      {
        path: 'AdvertisingChart',
        component: () => import('@/views/MediaAdvertisingChart/AdvertisingChart'),
        name: 'ExportExcel',
        meta: { title: '图片类型' }
      }
    ]
  },
  {
    path: '/Website informaction',
    component: Layout,
    redirect: 'Configure/configure',
    name: 'website information',
    meta: { title: '网站信息', icon: 'el-icon-set-up' },
    children: [
      {
        path: 'configure',
        component: () => import('@/views/Website information/Configure/configure'),
        name: 'Configure',
        meta: { title: '基础配置' }
      },
      {
        path: 'navigation',
        component: () => import('@/views/Website information/navigation'),
        name: 'Navigation',
        meta: { title: '导航管理' }
      },
      {
        path: 'consult',
        component: () => import('@/views/Website information/consult'),
        name: 'Consult',
        meta: { title: '在线咨询' }
      },
      {
        path: 'theme',
        component: () => import('@/views/Website information/theme'),
        name: 'Theme ',
        meta: { title: '更换主题色' }
      }
    ]
  },
  {
    path: '/sysmsg',
    component: Layout,
    redirect: '/sysmsg/index',
    name: 'sysmsg',
    meta: { title: '系统消息', icon: 'el-icon-postcard'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/sysmsg/index'),
        name: 'Sysmsg',
        meta: { title: '全站系统消息' }
      },
      {
        path: 'batch',
        component: () => import('@/views/sysmsg/batch'),
        name: 'Batch',
        meta: { title: '批量发送' }
      },
      {
        path: 'list of',
        component: () => import('@/views/sysmsg/list of'),
        name: 'ListOf ',
        meta: { title: '系统消息列表' }
      }
    ]
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/list',
    name: 'Example',
    meta: {
      title: '邮件管理',
      icon: 'el-icon-s-help'
    },
    children: [
      {
        path: 'create',
        component: () => import('@/views/example/create'),
        name: 'CreateArticle',
        meta: { title: '发送邮件', icon: 'edit' }
      },
      {
        path: 'list',
        component: () => import('@/views/example/list'),
        name: 'ArticleList',
        meta: { title: '邮件管理', icon: 'list' }
      }
    ]
  },
  {
    path: '/HelpCenter',
    component: Layout,
    redirect: '/HelpCenter/index',
    name: 'Helpcenter',
    meta: { title: '帮助中心', icon: 'clipboard' },
    children: [
      {
        path: 'index',
        component: () => import('@/views/HelpCenter/index'),
        name: 'HelpCenter',
        meta: { title: '新建帮助中心页面', icon: 'el-icon-folder-add' }
      },
      {
        path: 'HelpMenu',
        component: () => import('@/views/HelpCenter/HelpMenu'),
        name: 'HelpMenu',
        meta: { title: '帮助菜单', icon: 'el-icon-mobile' }
      }
    ]
  },
  {
    path: '/SMS',
    component: Layout,
    redirect: '/SMS/sms',
    name: 'SMS',
    meta: { title: '短信管理', icon: 'el-icon-s-promotion',roles:['admin'] },
    children: [
      {
        path: 'sms',
        component: () => import('@/views/SMS/sms'),
        name: 'sms',
        meta: { title: '发送短信', icon: 'el-icon-message' }
      },
      {
        path: 'smsManage',
        component: () => import('@/views/SMS/smsManage'),
        name: 'SmsManage',
        meta: { title: '短信管理', icon: 'el-icon-postcard' }
      }
    ]
  },
  {
    path: '/cache',
    component: Layout,
    redirect: '/HelpCenter/index',
    name: 'cache',
    meta: { title: '缓存管理', icon: 'el-icon-receiving' },
    children: [
      {
        path: 'index',
        component: () => import('@/views/cache/index'),
        name: 'Cache',
        meta: { title: '缓存管理', icon: 'el-icon-collection-tag' }
      }
    ]
  },
  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: ' ',
        meta: { title: '前端页面', icon: 'el-icon-paperclip' }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }

]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
 export const asyncRoutes = [
  {
    path: '/permission',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, // will always show the root menu
    name: 'Permission',
    meta: {
      title: 'Permission',
      icon: 'lock',
      roles: ['', 'editor'] // you can set roles in root nav
    },
    children: [
      {
        path: 'page',
        component: () => import('@/views/permission/page'),
        name: 'PagePermission',
        meta: {
          title: 'Page Permission',
          roles: ['admin'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'directive',
        component: () => import('@/views/permission/directive'),
        name: 'DirectivePermission',
        meta: {
          title: 'Directive Permission'
          // if do not set roles, means: this page does not require permission
        }
      },
      {
        path: 'role',
        component: () => import('@/views/permission/role'),
        name: 'RolePermission',
        meta: {
          title: 'Role Permission',
          roles: ['admin']
        }
      },
      {
        path: 'www',
        component: () => import('@/views/permission/www'),
        name: 'RolePermission',
        meta: {
          title: 'Role Permission',
          roles: ['www']
        }
      }
    ]
  }
  /*{
    path: '/zip',
    component: Layout,
    redirect: '/zip/download',
    alwaysShow: true,
    name: 'Zip',
    meta: { title: 'Zip', icon: 'zip' },
    children: [
      {
        path: 'download',
        component: () => import('@/views/zip/index'),
        name: 'ExportZip',
        meta: { title: 'Export Zip'}
      }
    ]
  },
*!/
  */
  /*{
    path: '/pdf',
    component: Layout,
    redirect: '/pdf/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/pdf/index'),
        name: 'PDF',
        meta: { title: 'PDF', icon: 'pdf' }
      }
    ]
  },
  {
    path: '/pdf/download',
    component: () => import('@/views/pdf/download'),
    hidden: true
  },*!/
  // 404 page must be placed at the end !!!

*/
]

export const managementRoutes =
  [
    TeachersRouter,
   /* AnswerRouter,
    applicationRouter,
    curriculumRouter,
    nestedRouter,
    statisticalRouter,
    studentRouter*/
  ]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465aaaaaaa
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
